import type {
  IArticleCategory,
  IArticleTag,
  ITotalInfo,
  IHomeInfo,
  IArticleItem,
  IArticleDetail,
} from "@/types/articleType";
import type { IResponse, IList, IResponsePage } from "@/types/utils";
import myRequest from "../index";

// 获取首页统计信息
function getHomeTotalInfo() {
  return myRequest.get<IResponse<ITotalInfo>>({
    url: "/app/base/comm/home_total",
  });
}

// 获取首页信息内容
function getHomeListInfo() {
  return myRequest.get<IResponse<IHomeInfo>>({
    url: "/app/base/comm/home_list",
  });
}

// 获取最新文章
function getArticleList(payload: { size: number; page: number }) {
  return myRequest.get<IResponsePage<IArticleItem[]>>({
    url: "/app/base/comm/article_list",
    params: payload,
  });
}

// 查询文章列表
function queryArticleList(payload: {
  size: number;
  page: number;
  keyWords?: string;
  isView?: number;
  isLike?: number;
  tag?: string;
  categoryId?: string;
}) {
  return myRequest.get<IResponsePage<IArticleItem[]>>({
    url: "/app/base/comm/article_list",
    params: payload,
  });
}

// 获取指定文章详情
function getArticleDetail(id: string) {
  return myRequest.get<IResponse<IArticleDetail>>({
    url: `/app/base/comm/article/${id}`,
  });
}

// 点赞文章
function likedArticle(id: string) {
  return myRequest.post<IResponse>({
    url: `/app/base/comm/article_like/${id}`,
  });
}
// 获取文章标签
function getArticleTagList() {
  return myRequest.get<IResponse<IArticleTag[]>>({
    url: "/app/base/comm/article_tag_list",
  });
}

// 获取文章分类
function getArticleCategory() {
  return myRequest.get<IResponse<IArticleCategory[]>>({
    url: "/app/base/comm/article_type_list",
  });
}

export {
  getHomeTotalInfo,
  getArticleList,
  queryArticleList,
  getArticleDetail,
  likedArticle,
  getHomeListInfo,
  getArticleTagList,
  getArticleCategory,
};
